home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / misc-src / clib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  1.5 KB  |  105 lines  |  [TEXT/EMAC]

  1. /*
  2.  * Copyright (C) 1993, 1994 Marc Parmet.
  3.  * This file is part of the Macintosh port of GNU Emacs.
  4.  *
  5.  * GNU Emacs is distributed in the hope that it will be useful,
  6.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8.  * GNU General Public License for more details.
  9.  */
  10.  
  11. #if defined(THINK_C)
  12. #include <MacHeaders>
  13. #else
  14. #include <Types.h>
  15. #include <Memory.h>
  16. #include <Quickdraw.h>
  17. #include <Windows.h>
  18. #endif
  19.  
  20. void
  21. pstrcpy(unsigned char *s,unsigned char *t)
  22. {
  23.     memcpy(s,t,t[0]+1L);
  24. }
  25.  
  26. void
  27. pstrcat(unsigned char *s,unsigned char *t)
  28. {
  29.     if ((long)s[0] + (long)t[0] > 255L) return;
  30.     memcpy(s+s[0]+1,t+1,(long)t[0]);
  31.     s[0] += t[0];
  32. }
  33.  
  34. int
  35. pstrcmp(unsigned char *s,unsigned char *t)
  36. {
  37.     int i;
  38.  
  39.     i = 1;
  40.     while (1) {
  41.         if (i-1 == s[0])
  42.             if (i-1 == t[0])
  43.                 return 0;
  44.             else
  45.                 return t[i];
  46.         else
  47.             if (i-1 == t[0])
  48.                 return -s[i];
  49.             else
  50.                 if (s[i] != t[i])
  51.                     return t[i] - s[i];
  52.                 else
  53.                     ++i;
  54.     }
  55. }
  56.  
  57. int
  58. atoi(char *s)
  59. {
  60.     int i;
  61.     int neg;
  62.     
  63.     while (*s == ' ' || *s == '\t' || *s == '\015' || *s == '\012')
  64.         ++s;
  65.  
  66.     if (*s == '-')
  67.         neg = 1, ++s;
  68.     else
  69.         neg = 0;
  70.     
  71.     i = 0;
  72.     while (*s >= '0' && *s <= '9') {
  73.         i = 10 * i + (*s - '0');
  74.         ++s;
  75.     }
  76.     
  77.     return neg ? -i : i;
  78. }
  79.  
  80. char *
  81. index(char *s,int t)
  82. {
  83.     char *strchr();
  84.     return strchr(s,t);
  85. }
  86.  
  87. char *
  88. rindex(char *s,int t)
  89. {
  90.     char *strrchr();
  91.     return strrchr(s,t);
  92. }
  93.  
  94. int
  95. random()
  96. {
  97.     return Random() << 16 | Random();
  98. }
  99.  
  100. void
  101. srandom(int seed)
  102. {
  103.     qd.randSeed = seed;
  104. }
  105.